package com.pubinfo.passbook.engine.process.variable.medicine;

import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import com.pubinfo.passbook.common.model.ruler.PayInformation;
import com.pubinfo.passbook.common.service.ruler.CheckService;
import com.pubinfo.passbook.common.utils.ApplicationContextUilts;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.List;

/**
 * 自费总和
 *
 * @author zhouch
 * @date 2022/2/22 15:21
 */
@Slf4j
public class CostSumAmountProcessor extends MedicineVariableProcessor {


    CheckService ruleService;

    public CostSumAmountProcessor() {
        ruleService = ApplicationContextUilts.getBean(CheckService.class);
    }

    @Override
    public String getName() {
        return "自费总和";
    }

    @Override
    public BigDecimal get(MedicineOnJobOrRetireDTO data) {

        log.info("执行参数处理器: {}", this.getClass().getSimpleName());

        List<PayInformation> payInformations = cache.getPayInformationData();

        BigDecimal sumAllAmountSelfs = BigDecimal.ZERO;

        for (PayInformation payInformation : payInformations) {

            BigDecimal sumAllAmountSelf = payInformation.getSelfpaymentCost(); //所有自费
            if (sumAllAmountSelf.equals(new BigDecimal(-0.0000999))) {
                cache.markNeedAudit();
                log.info("{} ==> 需要人工审核.", getClass().getSimpleName());
                sumAllAmountSelf = BigDecimal.ZERO;
            }
            sumAllAmountSelfs = sumAllAmountSelfs.add(sumAllAmountSelf);
        }

        log.info("参数处理器: {} 结果: {}", this.getClass().getSimpleName(), sumAllAmountSelfs);

        outputComputeMessage(sumAllAmountSelfs.toString());
        return sumAllAmountSelfs;
    }
}
